function showDiv(elementId) {
	var mask = document.getElementById('mask');
	mask.style.display = "";
	var element = document.getElementById(elementId);
	element.style.display = "";
}
function hiddenDiv(elementId) {
	var mask = document.getElementById('mask');
	mask.style.display = "none";
	var element = document.getElementById(elementId);
	element.style.display = "none";
}
function sign(id) {
	var inoutIds = document.getElementsByName('inoutId');
	for ( var i = 0; i < inoutIds.length; i++) {
		var inoutId = inoutIds.item(i);
		if (inoutId.value == id) {
			inoutId.checked = true;
			break;
		}
	}
}
function insertButton() {
	clearValue();
	showDiv('sus');
}
function updateButton() {
	var inoutIds = document.getElementsByName('inoutId');
	var id = 0;
	for ( var i = 0; i < inoutIds.length; i++) {
		var inoutId = inoutIds.item(i);
		if (inoutId.checked == true) {
			id = inoutId.value;
			break;
		}
	}
	update(id);
}
function deleteButton() {
	deleteInout();
}
function selectButton() {
	clearValue();
	showDiv('sus');
	document.getElementById("add").style.display = "none";
	document.getElementById("modify").style.display = "none";
	document.getElementById("find").style.display = "";
}
function update(id, trid) {
	document.getElementById("add").style.display = "none";
	document.getElementById("modify").style.display = "";
	document.getElementById("find").style.display = "none";
	if (id != 0) {
		showDiv('sus');
	} else {
		alert("请选择仓库");
	}
	var trElement = document.getElementById('' + trid);
	var str = '';
	var tds = trElement.getElementsByTagName('td');
	var inoutId = tds.item(0).getAttribute('inoutId');
	var inoutContact = tds.item(0).getAttribute('inoutContact');
	var inoutCompanyName = tds.item(0).getAttribute('inoutCompanyName');
	var inoutTel = tds.item(0).getAttribute('inoutTel');
	var inoutAdd = tds.item(0).getAttribute('inoutAdd');
	var inoutMemo = tds.item(0).getAttribute('inoutMemo');
	var inoutType = tds.item(0).getAttribute('inoutType');
	str = inoutId + '.' + inoutContact + '.' + inoutCompanyName + '.'
			+ inoutTel + '.' + inoutAdd + '.' + inoutMemo + '.' + inoutType;
	var strArr = str.split('.');
	setValue(strArr);
}
function clearValue() {
	document.getElementById("add").style.display = "";
	document.getElementById("modify").style.display = "none";
	document.getElementById("find").style.display = "none";
	$("#inoutId").val("");
	document.all.inoutCompanyName.value = "";
	document.all.inoutContact.value = "";
	document.all.inoutTel.value = "";
	document.all.inoutAdd.value = "";
	document.all.inoutMemo.value = "";
	document.all.inoutType.value = "";
}
function setValue(strArr) {
	$("#inoutId").val(strArr[0]);
	document.all.inoutContact.value = strArr[1];
	document.all.inoutCompanyName.value = strArr[2];
	document.all.inoutTel.value = strArr[3];
	document.all.inoutAdd.value = strArr[4];
	document.all.inoutMemo.value = strArr[5];
	document.all.inoutType.value = strArr[6];
}
function callback(data) {
	if ("" != data.lenght) {
		hiddenDiv('sus');
	}
	var str = "";
	for ( var i = 0; i < data.length; i++) {
		// 动态的改变页面中div节点中的内容
		str = str + '<tr id="tr' + i + '" ondblclick="update('
				+ data[i].inoutId + ',\'tr' + i + '\');" onclick="sign('
				+ data[i].inoutId + ');">' + '<td width="20" inoutId="'
				+ data[i].inoutId + '" inoutCompanyName="'
				+ data[i].inoutCompanyName + '" inoutTel="' + data[i].inoutTel
				+ '" inoutAdd="' + data[i].inoutAdd + '" inoutMemo="'
				+ data[i].inoutMemo + '" inoutContact="' + data[i].inoutContact
				+ '" inoutType="' + data[i].inoutType
				+ '"><input type="radio" name="inoutId" value="'
				+ data[i].inoutId + '" /></td>' + '<td width="100" >'
				+ data[i].inoutCompanyName + '</td>' + '<td width="70" >'
				+ data[i].inoutContact + '</td>' + '<td width="80" >'
				+ data[i].inoutTel + '</td>' + '<td width="200" >'
				+ data[i].inoutAdd + '</td>' + '<td width="92" >'
				+ data[i].inoutMemo + '</td>' + '</tr>';
	}

	clearValue();
	$("#inoutList").html(str);
}
// 添加 员工 部分
function createInout() {
	var inoutCompanyName = escape(escape($("#inoutCompanyName").val()));
	var inoutContact = escape(escape($("#inoutContact").val()));
	var inoutTel = escape(escape($("#inoutTel").val()));
	var inoutAdd = escape(escape($("#inoutAdd").val()));
	var inoutMemo = escape(escape($("#inoutMemo").val()));
	var j = 0;
	var url = '/stock/pages/system/inout.do?method=createInout&d=' + new Date()
			+ '&inoutCompanyName=' + inoutCompanyName + '&inoutContact='
			+ inoutContact + '&inoutTel=' + inoutTel + '&inoutAdd=' + inoutAdd
			+ '&inoutMemo=' + inoutMemo;
	$.getJSON(url, {}, callback);
}
// 修改 员工 部分
function updateInout() {
	var inoutId = $("#inoutId").val();
	var inoutCompanyName = escape(escape($("#inoutCompanyName").val()));
	var inoutContact = escape(escape($("#inoutContact").val()));
	var inoutTel = escape(escape($("#inoutTel").val()));
	var inoutAdd = escape(escape($("#inoutAdd").val()));
	var inoutMemo = escape(escape($("#inoutMemo").val()));
	var url = '/stock/pages/system/inout.do?method=updateInout&d=' + new Date()
			+ '&inoutId=' + inoutId + '&inoutCompanyName=' + inoutCompanyName
			+ '&inoutContact=' + inoutContact + '&inoutTel=' + inoutTel
			+ '&inoutAdd=' + inoutAdd + '&inoutMemo=' + inoutMemo;
	$.getJSON(url, {}, callback);
}
// 删除 员工 部分
function deleteInout() {
	if (confirm("真的要删除吗？删除后将无法恢复！")) {
		var inoutIdBox = document.getElementsByName("inoutId");
		var inoutId = 0;
		for ( var i = 0; i < inoutIdBox.length; i++) {
			if (inoutIdBox[i].checked) {
				isOper = inoutIdBox[i].isOper;
				inoutId = inoutIdBox[i].value;
				break;
			}
		}
		var url = '/stock/pages/system/inout.do?method=deleteInout&d='
				+ new Date() + '&inoutId=' + inoutId + '&isOper=' + isOper;
		$.getJSON(url, {}, callback);
	}
}
// 查找 员工 部分
function selectInout() {
	var inoutId = $("#inoutId").val();
	var inoutCompanyName = escape(escape($("#inoutCompanyName").val()));
	var inoutContact = escape(escape($("#inoutContact").val()));
	var inoutTel = escape(escape($("#inoutTel").val()));
	var inoutAdd = escape(escape($("#inoutAdd").val()));
	var inoutMemo = escape(escape($("#inoutMemo").val()));
	var url = '/stock/pages/system/inout.do?method=selectInout&d=' + new Date()
			+ '&inoutId=' + inoutId + '&inoutCompanyName=' + inoutCompanyName
			+ '&inoutContact=' + inoutContact + '&inoutTel=' + inoutTel
			+ '&inoutAdd=' + inoutAdd + '&inoutMemo=' + inoutMemo;
	$.getJSON(url, {}, callback);
}
function selectAllInout() {
	var url = '/stock/pages/system/inout.do?method=selectInout&d=' + new Date();
	$.getJSON(url, {}, callback);
}